/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ch.easer.zlv.jsf;

import ch.easer.zlv.ZahlungFacade;
import ch.easer.zlv.entity.enums.Haeufigkeit;
import ch.easer.zlv.entity.enums.Waehrung;
import ch.easer.zlv.entity.Zahlung;
import ch.easer.zlv.entity.enums.ZahlungsArt;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

/**
 *
 * @author easy
 */
@ManagedBean
@ViewScoped
public class ZahlungBean implements Serializable {

    @EJB
    private ZahlungFacade zahlungFacade;
    private Zahlung selectedListItem;
    private Zahlung selectedEditItem = new Zahlung();
    private List<Zahlung> items;
    private boolean listSelected = false;
    private boolean tabChartsDisabled = true;

    @PostConstruct
    public void init() {
        System.out.println("new BEAN:" + ZahlungBean.class.getName() + "__" + this.hashCode());
        items = zahlungFacade.findAll();
        if (!items.isEmpty()){
           setTabChartsDisabled(false); 
        }else{
          setTabChartsDisabled(true);   
        }
             
    }

    public boolean isListSelected() {
        return listSelected;
    }

    public void setListSelected(boolean listSelected) {
        this.listSelected = listSelected;
    }

    public boolean isTabChartsDisabled() {
        return tabChartsDisabled;
    }

    public void setTabChartsDisabled(boolean tabChartsDisabled) {
        this.tabChartsDisabled = tabChartsDisabled;
    }

    public Zahlung getSelectedEditItem() {
        return selectedEditItem;
    }

    public void setSelectedEditItem(Zahlung selectedEditItem) {
        this.selectedEditItem = selectedEditItem;
    }

    public Zahlung getSelectedListItem() {
        return selectedListItem;
    }

    public void setSelectedListItem(Zahlung selectedListItem) {
        this.selectedListItem = selectedListItem;
        if (selectedListItem != null) {
            this.selectedEditItem = selectedListItem;
            this.setListSelected(true);
        } else {
            selectedEditItem = new Zahlung();
            this.setListSelected(false);
        }
    }

    public List<Zahlung> getZahlungen() {
        return items;
    }

    public String deleteEntity() {
        if (this.getSelectedListItem() != null) {
            zahlungFacade.remove(this.getSelectedListItem());
            setSelectedListItem(null);
            init();
        }
        return null;
    }

    public String saveEntity() {
        zahlungFacade.edit(this.getSelectedEditItem());
        init();
        return null;
    }

    public String createEntity() {
        zahlungFacade.create(this.getSelectedEditItem());
        init();
        return null;
    }

    public List getWaehrungen() {
        ArrayList list = new ArrayList();
        list.addAll(Arrays.asList(Waehrung.values()));
        return list;
    }

    public List getHaeufigkeiten() {
        ArrayList list = new ArrayList();
        list.addAll(Arrays.asList(Haeufigkeit.values()));
        return list;
    }
    
    public List getZahlungsarten() {
        ArrayList list = new ArrayList();
        list.addAll(Arrays.asList(ZahlungsArt.values()));
        return list;
    }
    
    public String reset(){
        return "zahlungen.wiederkehrend.xhtml?faces-redirect=true";
    }
    
}
